//
//  OVELoginView.m
//  AddressBook Objective-C
//
//  Created by 王璐 on 2018/11/7.
//  Copyright © 2018 Ove. All rights reserved.
//

#import "OVELoginView.h"
#import "Masonry.h"

@implementation OVELoginView

+(instancetype)loginViewWithFrame:(CGRect)frame {
    return  [[self alloc] initWithFrame:frame];
}

-(instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    
    if (self) {
        [self setupUI];
    }
    
    return self;
}

-(void)setupUI {
    self.backgroundColor = [UIColor whiteColor];
    
    //userLabel
    UILabel *userLabel = [[UILabel alloc] init];
    userLabel.text = @"账号:";
    [self addSubview:userLabel];
    self.userLabel = userLabel;
    
    [userLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(50);
        make.top.mas_equalTo(150);
        make.height.mas_equalTo(30);
    }];
    
    //userTF
    UITextField *userTF = [[UITextField alloc] init];
    userTF.placeholder = @"请输入用户账号";
    userTF.borderStyle = UITextBorderStyleRoundedRect;
    [self addSubview:userTF];
    self.userTF = userTF;
    
    [userTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(userLabel.mas_right).offset(5);
        make.top.mas_equalTo(150);
        make.width.mas_equalTo(200);
    }];
    
    //pwdLabel
    UILabel *pwdLabel = [[UILabel alloc] init];
    pwdLabel.text = @"密码:";
    [self addSubview:pwdLabel];
    self.pwdLabel = pwdLabel;
    
    [pwdLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(50);
        make.height.mas_equalTo(30);
        make.top.mas_equalTo(200);
    }];
    
    //pwdTF
    UITextField *pwdTF = [[UITextField alloc] init];
    pwdTF.placeholder = @"请输入用户密码";
    pwdTF.borderStyle = UITextBorderStyleRoundedRect;
    [self addSubview:pwdTF];
    self.pwdTF = pwdTF;

    [pwdTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(pwdLabel.mas_right).offset(5);
        make.top.mas_equalTo(200);
        make.width.mas_equalTo(200);

    }];
    
    //remberLabel
    UILabel *remberLabel = [[UILabel alloc] init];
    remberLabel.text = @"记住密码";
    [self addSubview:remberLabel];
    self.remberLabel = remberLabel;
    
    [remberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(pwdTF.mas_bottom).offset(70);
        make.left.mas_equalTo(10);
        make.height.mas_equalTo(30);
    }];
    
    //remberSwitch
    UISwitch *remberSwitch = [[UISwitch alloc] init];
    remberSwitch.onTintColor = [UIColor greenColor];
    remberSwitch.thumbTintColor = [UIColor blueColor];
//    remberSwitch.tintColor = [UIColor redColor];
    [self addSubview:remberSwitch];
    self.remberSwitch = remberSwitch;
    
    [remberSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(remberLabel.mas_top);
        make.left.equalTo(remberLabel.mas_right).offset(5);
    }];
    
    //autoLoginLabel
    UILabel *autoLoginLabel = [[UILabel alloc] init];
    autoLoginLabel.text = @"自动登录";
    [self addSubview:autoLoginLabel];
    self.autoLoginLabel = autoLoginLabel;
    
    [autoLoginLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(remberSwitch.mas_top);
        make.left.equalTo(remberSwitch.mas_right).offset(30);
        make.height.mas_equalTo(30);
    }];
    
    //autoLoginSwitch
    UISwitch *autoLoginSwitch = [[UISwitch alloc] init];
    autoLoginSwitch.onTintColor = [UIColor greenColor];
    autoLoginSwitch.thumbTintColor = [UIColor blueColor];;
    [self addSubview:autoLoginSwitch];
    self.autoLoginSwitch = autoLoginSwitch;
    
    [autoLoginSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(autoLoginLabel.mas_top);
        make.left.equalTo(autoLoginLabel.mas_right).offset(5);
    }];
    
    //loginBtn
    UIButton *loginBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [loginBtn setTitle:@"登 录" forState:UIControlStateNormal];
    [loginBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    loginBtn.frame = CGRectMake(0, 0, 100, 30);
    loginBtn.center = self.center;
    loginBtn.enabled = NO;
    loginBtn.backgroundColor = [UIColor blueColor];
    [self addSubview:loginBtn];
    self.loginBtn = loginBtn;
    
    
}

@end
